chore: use ICU for relative dateime formatting#1146
Merged
Conversation
Reviewer's GuideThis PR replaces manual string concatenation for relative date/time displays with ICU’s locale-aware RelativeDateTimeFormatter and SimpleDateFormat, adds utility converters between QString and icu::UnicodeString, and updates CMake and packaging to include ICU dependencies. Sequence Diagram: Relative Time Formatting with ICU in AppNotifyItemsequenceDiagram
title "Sequence Diagram: Relative Time Formatting with ICU in AppNotifyItem"
participant A as "AppNotifyItem"
participant RDF as "icu::RelativeDateTimeFormatter"
participant SDF as "icu::SimpleDateFormat"
participant Conv as "StringConversionUtils"
A ->> A: updateTime()
A ->> RDF: create(Locale::getDefault(), ..., UDAT_STYLE_LONG, ...)
alt If time is within minutes/hours (same day)
A ->> RDF: format(value, UDAT_DIRECTION_LAST, UDAT_RELATIVE_MINUTES/HOURS, result, status)
A ->> Conv: toQString(result)
Conv -->> A: formattedTime : QString
else If time is "Yesterday"
A ->> RDF: format(1, UDAT_DIRECTION_LAST, UDAT_RELATIVE_DAYS, dateResult, status)
A ->> SDF: create("HH:mm", Locale::getDefault(), status)
A ->> SDF: format(m_entity.cTime(), timeString, status)
A ->> RDF: combineDateAndTime(dateResult, timeString, combinedResult, status)
A ->> Conv: toQString(combinedResult)
Conv -->> A: formattedTime : QString
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @BLumia - I've reviewed your changes - here's some feedback:
- Consider moving the ICU RelativeDateTimeFormatter and SimpleDateFormat instances out of updateTime (e.g. as static or member variables) to avoid recreating them on every call and improve performance.
- After each ICU operation you should check UErrorCode (status and timeStatus) and handle or log errors to avoid silent formatting failures.
Here's what I looked at during the review
- 🟡 General issues: 4 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
43dc5d8 to
56fd120
Compare
使用 ICU 提供相对时间格式的时间展示,避免拼接字符串造成不易于本地化 的问题. Log:
56fd120 to
0d0b3d9
Compare
deepin pr auto review关键摘要:
是否建议立即修改:
|
18202781743
approved these changes
Jun 9, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, BLumia The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
使用 ICU 提供相对时间格式的时间展示,避免拼接字符串造成不易于本地化的问题.
Summary by Sourcery
Use ICU libraries to provide localized relative datetime formatting in notification items, replacing manual string concatenation for improved i18n support.
Enhancements:
Build: